package com.ruoyi.drone.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.drone.domain.DroneUserProfile;
import com.ruoyi.drone.mapper.DroneUserProfileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

/**
 * 飞手相关接口
 */
@RestController
@RequestMapping("/drone/pilot")
public class DronePilotController extends BaseController {

    @Autowired
    private DroneUserProfileMapper droneUserProfileMapper;

    /**
     * 查询当前登录用户的飞手档案信息
     */
    @GetMapping("/me")
    public AjaxResult getMyProfile(HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        if (userId == null) {
            return AjaxResult.error("未登录或用户信息缺失");
        }
        DroneUserProfile profile = droneUserProfileMapper.selectDroneUserProfileByUserId(userId);
        if (profile == null) {
            return AjaxResult.success(null); // 前端据此判断为非飞手或未注册
        }
        return AjaxResult.success(profile);
    }
}
